import logging

import allure
import pytest

from api.ArticleModule.CreateArticleTypesApi import CreateArticleTypesApi
from api.ArticleModule.DeleteArticleTypesApi import DeleteArticleTypesApi
from utils.AllureAttachReqRespUtil import AllureAttachReqRespUtil


@allure.epic('大模块标题')
@allure.feature("次一级的模块")
@allure.story("再次一级别的模块")
@allure.description('erp系统接口自动化')
@pytest.mark.run(order=1)
@allure.severity(allure.severity_level.BLOCKER)
@pytest.mark.smoke
class TestArticle:

    article_name = None

    # def test_create(self):
    #     response = CreateArticleTypesApi().create_article_type()
    #     print("---------------------")
    #     TestArticle.article_name = response.json()["metadata"]["name"]
    #     print("-------------")
    #     print(TestArticle.article_name)
    #     assert response.status_code == 201

    @pytest.mark.dependency(name="testArticle")
    @allure.title("新增文章分类接口")
    @allure.step("新增文章分类接口")
    @allure.severity(allure.severity_level.BLOCKER)
    @allure.testcase("https://www.abidu.com", "新增文章分类接口测试用例地址")
    def test_create(self):
        response = CreateArticleTypesApi().create_article_type()
        AllureAttachReqRespUtil.attach_request_response(response.request, response)
        # print("---------------------")
        logging.info("response: {}".format(response))
        pytest.name = response.json()["metadata"]["name"]
        # print("-------------")
        # print(pytest.name)
        assert response.status_code == 200

    @pytest.mark.dependency(depends=["testArticle"])
    @allure.title("删除文章分类接口")
    @allure.step("删除文章分类接口")
    @allure.severity(allure.severity_level.BLOCKER)
    @allure.testcase("https://www.abidu.com", "删除文章分类接口测试用例地址")
    def test_delete(self):
        response = DeleteArticleTypesApi().delete_article_types(pytest.name)
        AllureAttachReqRespUtil.attach_request_response(response.request, response)
        # print(response.json())
        logging.info("response: {}".format(response.json()))
        assert response.status_code == 200







